package main

import (
	"fmt"
	"math/rand"
	"time"
)

//for循环
func main() {
	//oneToMax(1000)
	randomMax(100, 10000)
	att := [5]int{55, 21, 48, 46, 31}
	bubblingSort(&att)
}

//如何生成1-100整数
func randomMax(max int, count int) int {
	rand.Seed(time.Now().Unix())
	for i := 0; i < count; i++ {
		//生成随机数,rand设置一个种子
		//time.Now().Unix():返回一个从1970:01:01 的0时0分0秒
		n := rand.Intn(max + 1)
		fmt.Println("随机数=", n)
		if n == 50 {
			fmt.Println("N当前值刚好是=", n, "结束循环")
			break
		}
	}
	return 0
}

//打印1~100之间所有是9的倍数的证书的个数及总和
func oneToMax(max int) (int, int) {
	sum := 0
	size := 0
	for i := 0; i < max; i++ {
		if i%9 == 0 && i != 0 {
			fmt.Println(i, "是9的倍数")
			sum += i
			size++
		}
	}
	fmt.Println("总和=", sum, "总个数=", size)
	return sum, size
}

func strLong(max string) {

}

//for循环

func bubblingSort(att *[5]int) {
	fmt.Println("原始数组:", att)
	temp := 0
	for j := 0; j < len(att); j++ {
		for i := 0; i < len(att)-1-j; i++ {
			if att[i] > att[i+1] {
				temp = att[i]
				att[i] = att[i+1]
				att[i+1] = temp
			}
		}
	}

	fmt.Println("排序后:", att)
}
